<div class="right_side_operate_area">
    <?php  
        if($showpage==1) {
            if(isset($paging)){ echo $this->renderElement('pagination',$paging);} 
        }
    ?>

    <?php 
        $user=$session->read('User');
        $isadd=$action->checkPermissions($user,"add");
        //print_r($isadd);
    ?>
    <?php
        if($isadd)
        {
            echo '<div class="left item_add_btn">';
            echo $html->link(__("Add",true),"/projects/editinfo/");
            echo '</div>';
        }else{
            echo '<div class="left enableaction">';
            echo "<a>添加</a>";
            echo '</div>';
        }
    ?>
    <div class="term_choose_area left">
        <a class="term_choose_btn" id="term_choose_btn"  title="选择"></a>
        <div class="screen_list" id="screen_list" style="display:none;visibility:hidden;">
            <ul>
                <?php 
                foreach($industrys as $key=>$strindustry){
                    $selected="";
                    if($industry==$key){
                        $selected="selected";
                    }
                    echo '<li class="'.$selected.'">';
                    echo $html->link($strindustry,"javascript:void(0);",array("onclick"=>"return setindustry('".$key."')","class"=>$selected));
                    echo '</li>';
                }
                ?>
            </ul>
            <div id="industry" style="display:none"><?php echo $industry?></div>
        </div>
    </div>

    <div class="left search_box">
        <form onsubmit="return searchproject()">
            <div class="left search_text">
                <?php echo $form->text('Project.keyword',array('placeholder'=>'搜索项目或企业名称','value'=>$keyword, 'id'=>'projectkey', 'class'=>'text_box'));?>
            </div>
            <div class="left search_btn"><input type="submit" value=""/></div>
        </form>
        <div class="clear"></div>
    </div>
	
    <div class="right_side_title left" style='width:100%;'>
        <?php 
                $askfor_state = array(""=>"请选择移交状态","0"=>"未移交","1"=>"已移交","2"=>"申请移交","3"=>"已驳回申请");
                echo $form->select('ddlaskforstate',$askfor_state, $askforstate, null,null);
        ?>
        
        <?php 
                $delete_state = array(""=>"请选择删除状态","0"=>"未删除","2"=>"申请删除","3"=>"已驳回删除");
                echo $form->select('ddldeletestate',$delete_state, $deletestate, null,null);
        ?>
    
    
        <?php 
            $objfirst_owner=array();
            $objfirst_owner['']="请选择负责人";
            $first_owner="";
            if(!empty($_GET["first_owner"])){
                $first_owner=$_GET["first_owner"];
            }
            if($objusers){
                foreach($objusers as $users){
                	$objfirst_owner[$users["User"]["id"]]=$users["User"]["name"];
            	}
            }
            echo $form->select('ddlfirst_owner',$objfirst_owner, $first_owner, null,null);
            
          if($user['isadmin']||$user['isvisitor']){
			$grouplist=array_merge(array(""=>"请选择模块"),$grouplist);
	    	echo $form->select('ddlgroup',$grouplist,$group_mod_id, null,null);
	 		}
        ?>
        <?php 
            echo $form->select('ddlphase',$objphase, $phase, null,null);
        ?>
        <?php 
            if($Registr){
                $objregistr=classregistry::init('Codetype')->getCValues($Registr);
                $registr="";
                if(!empty($_GET["registr"])){
                    $registr=$_GET["registr"];
                }
                echo $form->select('ddlregistr',$objregistr, $registr, null,null);
            }
        ?>
    </div>
    <div class="clear"></div>
</div>

<div class="right_side_scollbar">
    <div class="detail_info_panel">
        <div class="items_list">
            <table cellpadding='0' cellspacing='0' >
                <tr >
                    <th><?php __("Project Name")?></th>
                    <th><?php __("Company Name")?></th>
                    <th><?php __("In Phase")?></th>
                    <th><?php __("Owner")?></th>
                    <th>移交</th>
                    <th>删除</th>
                    <th>创建时间</th>
                    <th><?php __("Action")?></th>
                </tr>
                <?php
                foreach($projects as $project){
                    $id=$project["Project"]["id"];
                    $project_name=$project["Project"]["project_name"];
                    echo "<tr class='per_list'>";
                    echo "<td>".$html->link($project_name,"/projects/showinfo/".$id,null,null)."</td>";
                    echo "<td>".$project["Project"]["company_name"]."</td>";
                    echo "<td>".$project["phase_cvalue"]["value"]."</td>";
                    echo "<td>".$accp->getusername($objusers,$project["Project"]["first_owner"])."</td>";
                    //$second_owners=$accp->getusername($objusers,$project["Project"]["second_owner"]);
                    //echo "<td>".$second_owners."</td>";
                    
                    echo "<td>";
                    $is_audit=$project["Project"]["is_audit"];
                    if($is_audit == "0") $audit = "否";
                    else if($is_audit == "1") $audit = "是";
                    else if($is_audit == "3") $audit = "驳回";
                    else $audit = "申请中";
                    echo $audit;
                    //echo $str->getflag($is_audit);
                    echo "</td>";
                    
                    echo "<td>";
                    $is_deleted = $project["Project"]["is_deleted"];
                    if($is_deleted == "0") $deleted = "否";
                    else if($is_deleted == "2") $deleted = "申请中";
                    else if($is_deleted == "3") $deleted = "驳回";
                    echo $deleted;
                    echo "</td>";
                    
                    echo "<td>".date("Y-m-d",strtotime($project["Project"]["created"]))."</td>";
                    echo "<td>";
                    if($user["isadmin"] || $user["isgroupadmin"])
                    {
                        echo $html->link(__("Edit",true),"/projects/editinfo/".$id,null,null);
                    }
                    else
                    {
                        if(($is_audit == "0" || $is_audit == "3") && $project["Project"]["first_owner"] == $user["id"])
                        {
                            echo $html->link(__("Edit",true),"/projects/editinfo/".$id,null,null);
                        }
                        else 
                        {
                            echo "<span class='enableaction'>编辑</span>";
                        }
                    }
                    
                    if($user["isadmin"] || $user["isgroupadmin"]){
                        echo $html->link(__("Delete",true),"/projects/dels/".$id,array("onclick"=>"return doaction(this)"));
                    }else if($project["Project"]["first_owner"] == $user["id"] && ($is_deleted == "0" || $is_deleted == "3") && ($is_audit != "2") && $is_audit != "1"){
                        echo $html->link("申请删除","/projects/editIsdeleted/".$id,array("onclick"=>"return doaction(this)"));
                    }else{
                        echo "<span class='enableaction'>删除</span>";
                    }
                    
                    echo "</td>";
                    echo "</tr>";
                }?>
            </table>
        </div>
    </div>
</div>

<?php
    if($user["isadmin"] || $user["isgroupadmin"])
        echo $this->element('actionconfirm',array("title"=>"删除提示","message"=>"你确定要删除吗？"));
    else
        echo $this->element('actionconfirm',array("title"=>"申请删除提示","message"=>"你确定要申请删除吗？"));
?>
<?php echo $this->element('autocomplete',array("model_name"=>"Project","field_name"=>"project_name","widget_name"=>"projectkey")) ?>

<script>
function focuseEV(C,B,A){
    if(window.attachEvent){
        C.attachEvent("on"+B,A);
    }else{
        if(window.addEventListener){
            C.addEventListener(B,A,false);
        }
    }
}
focuseEV(document,"click",function(E){
    var E=E||window.event;
    var A=E.target||E.srcElement;
    var D=window.event?E.button:E.which;
    var C=G("term_choose_btn"),B=G("screen_list");
    while(A&&A!=document.body&&A.tagName.toLowerCase()!="html"){
        if(A==C){break}
        if(A==B){break}
        A=A.parentNode
    }
    if(A==B){
    }else if(A!=C){
        B.style.display="none"
            B.style.visibility="hidden"
    }else{
        if(D<2){
            B.style.display=B.style.display=="block"?"none":"block";
            B.style.visibility=B.style.visibility=="hidden"?"visible":"hidden";
        }
    }
});
var webpath=$("#getpath").attr('href');
var urlpath=webpath+"projects/index?seach=all";
$(document).ready(function() {
	
    $("#ddlgroup").change(function() {  
        searchproject();
    });
    $("#ddlfirst_owner").change(function() {  
        searchproject();
    });
    $("#ddlphase").change(function() {  
        searchproject();
    });
    $("#ddlregistr").change(function() {  
        searchproject();
    });

    $("#ddlaskforstate").change(function(){
        searchproject();
    });
    
    $("#ddldeletestate").change(function(){
        searchproject();
    });
});
if($("#projectkey").val()!=""){
    $("#projectkey").focus();
}
function setindustry(inid){
    $("#industry").html(inid);
    return searchproject();
}
function searchproject()
{	
    var first_owner=$("#ddlfirst_owner").val();
    var phase=$("#ddlphase").val();
    var strphase=$("#ddlphase").find("option:selected").text();
    var nreg = "<?php echo $nreg;?>";
    var wreg = "<?php echo $wreg;?>";
    var registr;
    if(strphase != nreg && strphase != wreg)
        registr = "";
    else
        registr=$("#ddlregistr").val();
    var projectkey=$("#projectkey").val();
    var askforstate = $("#ddlaskforstate").val();
    var deletestate = $("#ddldeletestate").val();
    var inid=$("#industry").html();
    var group=$("#ddlgroup").val();
    
    if(group==""&& first_owner=="" && phase=="" && registr=="" && projectkey=="" && inid=="" && askforstate=="" && deletestate==""){
        location.href=urlpath;
    }else{
        if(group!=""){
        	urlpath+="&group="+group;
            }
        if(first_owner!=""){
            urlpath+="&first_owner="+first_owner;
        }
        if(phase!=""){
            urlpath+="&phase="+phase;
        }
        if(registr!="" && registr!=null){
            urlpath+="&registr="+registr;
        }
        if(projectkey.trim()!=""){
            urlpath+="&keyword="+encodeURIComponent(projectkey.trim());
        }
        if(askforstate != ""){
            urlpath+="&askforstate="+askforstate;
        }
        if(deletestate != ""){
            urlpath+="&deletestate="+deletestate;
        }
        if(inid.trim()!=""){
            urlpath+="&industry="+inid.trim();
        }
        location.href=urlpath;
    }
    return false;
}
funPlaceholder(document.getElementById("projectkey"));
</script>